package com.example.travelhelper.service.serviceImpl;

import com.example.travelhelper.mapper.ArticleMapper;
import com.example.travelhelper.mapper.CustomerSeMapper;
import com.example.travelhelper.pojo.Article;
import com.example.travelhelper.pojo.CustomerService;
import com.example.travelhelper.service.ArticleService;
import com.example.travelhelper.utils.RandomUtil;
import com.example.travelhelper.utils.ResponseData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.UUID;

@Service
public class ArticleServicImpl implements ArticleService {
    @Autowired
    ArticleMapper articleMapper;
    @Autowired
    CustomerSeMapper customerSeMapper;

    @Override
    public ResponseData get() {
        //暂时只有一篇文章
        try {
            Article article = articleMapper.selectById("0319dfc5-38d7-417c-84cb-229ad7fca3a4");
            if(article==null)
            {
                ResponseData.fail("请求失败");
            }

            return ResponseData.success("请求成功",article);

        }catch (Exception e){
            e.printStackTrace();
        }
   return      ResponseData.fail("请求失败");
    }

    @Override
    public ResponseData submit(Article article) {
        article.setArId("0319dfc5-38d7-417c-84cb-229ad7fca3a4");
//        List<CustomerService> customerServices = customerSeMapper.selectList(null);
//        article.setContent(article.getContent().replace("00000000000",customerServices.get(RandomUtil.randomOid(customerServices.size())).getCsTelephone()));
        articleMapper.updateById(article);
        Article article1 = articleMapper.selectById("0319dfc5-38d7-417c-84cb-229ad7fca3a4");
           return ResponseData.success("提交成功",article1);
    }
}
